package com.xian.common.excel.demo;

import com.xian.common.excel.ExportExcel;
import com.xian.common.excel.annotation.ExcelField;
import lombok.Data;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 *
 * @Author: xlr
 * @Date: Created in 下午10:40 2019/2/19
 */
@Data
public class ExcelSourseVo implements Serializable{

    @ExcelField( title = "year",align= 2,sort= 0)
    private String year;

    @ExcelField( title = "month",align= 2,sort= 0)
    private String month;

    @ExcelField( title = "blank",align= 2)
    private Integer blank = 0;

    @ExcelField( title = "retail&active",align= 2)
    private Integer active = 0;

    @ExcelField( title = "retail& terminated",align= 2)
    private Integer terminated = 0;

    @ExcelField( title = "preactivation&waived",align= 2)
    private Integer waived = 0;

    @ExcelField( title = "SUM",align= 2)
    private Integer sum = 0;

    public Integer getSum(){
        return blank+active+terminated+waived;
    }


    public static void main(String[] args) {

        String fileName = "/Users/tengyueyuangong/project/gitee/excel/"+ UUID.randomUUID().toString()+"模板"+".xlsx";
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(fileName);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //测试模板下载
        new ExportExcel("测试模板效果",ExcelSourseVo.class,2).write(fout).dispose();

        List<ExcelSourseVo> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ExcelSourseVo esv = new ExcelSourseVo();
            esv.setYear(i+"");
            esv.setActive(i);
            list.add(esv);
        }
        String fileName1 = "/Users/tengyueyuangong/project/gitee/excel/"+ UUID.randomUUID().toString()+"數據下載"+".xlsx";
        FileOutputStream fout1 = null;
        try {
            fout1 = new FileOutputStream(fileName1);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        new ExportExcel("测试数据下载", ExcelSourseVo.class, 1).setDataList(list).write(fout1).dispose();

    }
}
